home *** CD-ROM | disk | FTP | other *** search
/ Mission 3 / Mission 3.zip / Mission 3.iso / texte / 7up_pd / fileio5.c < prev    next >
C/C++ Source or Header  |  1998-10-29  |  47KB  |  2,159 lines

  1. /* Laden und Speichern von Dateien */
  2. /*****************************************************************************
  3. *
  4. *                                             7UP
  5. *                                      Modul: FILEIO.C
  6. *                                    (c) by TheoSoft '90
  7. *
  8. *****************************************************************************/
  9. #include <portab.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <ctype.h>
  14. #include <aes.h>
  15. #include <vdi.h>
  16.  
  17. #if GEMDOS
  18. #include <tos.h>
  19. #include <ext.h>
  20. /*
  21. #include "7up.rh"
  22. */
  23. #include "fsel_inp.h"
  24. #else
  25. #include <alloc.h>
  26. #include <dir.h>
  27. #include <dos.h>
  28. #include <io.h>
  29. #endif
  30.  
  31. #include "alert.h"
  32. #include "windows.h"
  33. #include "forms.h"
  34. #include "7UP.h"
  35.  
  36. #include "language.h"
  37.  
  38. extern WINDOW _wind[MAXWINDOWS];
  39.  
  40. typedef struct
  41. {
  42.     int menu,item;
  43. } UNDO;
  44.  
  45. int  WI_KIND=CLOSER|MOVER|NAME|INFO|FULLER|UPARROW|VSLIDE|DNARROW|SIZER|RTARROW|HSLIDE|LFARROW;
  46.  
  47. #define FILEIOBUFF (32*1024L)
  48. #define TEXT      0  /* windowtype */
  49. #define GRAPHIC  1
  50. #define PRT     0
  51. #define DESK      0
  52. #define TRUE      1
  53. #define FALSE    0
  54. #define VERTICAL 1
  55. #define CRLF 1
  56. #define LF    2
  57. #define CR    3
  58.  
  59. #define METAFILE 31
  60.  
  61. void showprogress(OBJECT *tree, long size, long len);
  62. int open_work (int device);
  63. void close_work (int handle, int device);
  64. int Wtxtdraw(register WINDOW *wp, int dir, int clip[]);
  65. int menu_ikey(OBJECT *m_tree, int kstate, int key);
  66. int editor(WINDOW *wp, int state, int key);
  67. void add_icon(OBJECT *tree, int icon);
  68. void ren_icon(OBJECT *tree, int icon);
  69. void del_icon(OBJECT *tree, int icon);
  70. void drag_icon(OBJECT *tree, int icon);
  71. void click_icon(OBJECT *tree, int icon);
  72. WINDOW *Wreadfile(char *name, int mode);
  73. WINDOW *Wnewfile(char *name);
  74. void Wdefattr(WINDOW *wp);
  75. char *split_fname(char *pathname);
  76. hndl_prtmenu(OBJECT *tree, WINDOW *wp);
  77. Dredraw(OBJECT *tree, int obj, int depth);
  78. int desk_fkey(OBJECT *tree,int ks,int kr);
  79. int Dhndlfkt(OBJECT *tree, int x, int y);
  80. int ins_line(WINDOW *wp);
  81. void paste_blk(WINDOW *wp, LINESTRUCT *beg, LINESTRUCT *end);
  82. int getfilename(char *pathname, char *pattern, char *fname, const char *meldung);
  83. int findlastspace(char *iostr, int umbruch, int abscol);
  84. void write_file(WINDOW *wp, int newname);
  85. char *change_ext(char *name, char *ext);
  86. char *change_name(char *name, char *newname);
  87. char *change_linealname(char *name, char *newname);
  88. WINDOW *Wreadtempfile(char *filename, int mode);
  89.  
  90. char *stpexpan(char *, char *, int, int, int *); /* expand TABS in a string */
  91. char *stptabfy(char *, int);                 /* Compress blanks to TABs.*/
  92.  
  93. long *get_cookie(long cookie);
  94.  
  95. int countdeletedfiles=0,bcancel,lineendsign,wret,eszet,tabexp;
  96.  
  97. extern OBJECT *winmenu,*prtmenu,*popmenu,
  98.                   *desktop,*findmenu,*gotomenu,
  99.                   *fontmenu,*tabmenu,*infomenu,
  100.                   *progress,*divmenu,*layout,
  101.                   *pinstall,*fselbox;
  102.  
  103. extern long begline,endline;
  104. extern int vdihandle,xdesk,ydesk,wdesk,hdesk,boxh;
  105. extern char alertstr[256];
  106. extern UNDO undo;
  107. extern int terminate_at_once;
  108.  
  109.  
  110. char iostring[STRING_LENGTH+3],iostr2[STRING_LENGTH+3];
  111.  
  112. #if GEMDOS
  113. int access(char *filename, int fattr)
  114. {
  115.     struct ffblk fileRec;
  116.     int ret;
  117.     
  118.    ret=findfirst(filename,&fileRec,fattr);
  119.     return(!ret);
  120. }
  121. #endif
  122.  
  123. void Wfree(WINDOW *wp)
  124. {
  125.     register LINESTRUCT *line /*,*lastline*/;
  126.     int newname=FALSE;
  127.  
  128.     if(wp)
  129.     {
  130.         countdeletedfiles++;
  131.         if(wp->fstr && !terminate_at_once) /* schnelles Beenden */
  132.         {
  133.             if(wp->w_state & CHANGED)
  134.             {
  135.                 sprintf(iostring,Afileio[0],split_fname((char *)Wname(wp)));
  136.                 if(form_alert(2,iostring)==2)
  137.                 {
  138.                     if(!strcmp((char *)Wname(wp),NAMENLOS))
  139.                         newname=TRUE;
  140.                      write_file(wp, newname);
  141.                 }
  142.             }
  143.             graf_mouse(BUSY_BEE,NULL);
  144.          while(wp->fstr!=NULL)
  145.          {
  146.             line=wp->fstr;
  147.             wp->fstr=line->next;
  148.                 free(line->string);
  149.             free(line);
  150.          }
  151.             graf_mouse(ARROW,NULL);
  152.         }
  153.         free(wp->name);
  154.         wp->name=NULL;
  155.         free(wp->info);
  156.         wp->info=NULL;
  157. #if GEMDOS
  158.         if(vq_gdos())
  159. #endif
  160.             if(wp->w_state & GEMFONTS)
  161.             {
  162.                 vst_unload_fonts(wp->vdihandle,0);
  163.                 wp->w_state &= ~GEMFONTS;
  164.                 wp->w_state &= ~PROPFONT;
  165.             }
  166.     }
  167. }
  168.  
  169. void complete_path(char *path)
  170. {
  171.     char *cp;
  172.     
  173.     if((cp=strchr(path,'/'))!=NULL)
  174.     {  /* Wenn ein Slash auftritt, so ist das der DIRSEP! */
  175.         if(path[strlen(path)-1]!='/')
  176.             strcat(path,"/"); /* Slash anhängen */
  177.     }
  178.     else
  179.     {    /* normaler Pfadname mit Backslash */
  180.         if(path[strlen(path)-1]!='\\')
  181.             strcat(path,"\\");
  182.     }
  183. }
  184.  
  185. void cut_path(char *path)
  186. {
  187.     char *cp;
  188.     if((cp=strrchr(path,'\\'))!=NULL || (cp=strrchr(path,'/'))!=NULL)
  189.         *(cp+1)=0;
  190. }
  191.  
  192. char *search_env(char *path, char *filename, int write)
  193. {
  194.     register char *cp;
  195.     if((cp=getenv("7UP"))!=NULL || 
  196.        (cp=getenv("SEVENUP"))!=NULL ||    /* wg. GEMINI 1.99 */
  197.        (cp=getenv("HOME"))!=NULL)
  198.     {
  199.         strcpy(path,cp);
  200.         complete_path(path);
  201.         strcat(path,filename);
  202. /* MT 8.9.94 shel_find() macht Probleme. Zugriff auf A: 
  203.         if(write) /* wenn schreiben, dann hier */
  204.             return(path);
  205.         if(shel_find(path))
  206.             return(path);
  207. */
  208.         return(path);
  209.     }
  210.     strcpy(path,filename);
  211.     return(path);
  212. }
  213.  
  214. int gettrashname(char *pathname, const char *meldung)
  215. {
  216.     int i,button;
  217.     char filename[FILENAME_MAX];
  218.  
  219.     filename[0]=0;
  220.     wind_update(BEG_UPDATE);
  221.     wind_update(BEG_MCTRL); /* wg, graf_slidebox() lt. Profibuch S.691 */
  222.  
  223. #if GEMDOS
  224.  
  225.     if(_GemParBlk.global[0] >= 0x0140 || get_cookie('FSEL'))
  226.     {
  227.         if(fsel_exinput(pathname,filename,&button,meldung))
  228.         {
  229.             if(button && strlen(filename))
  230.             {
  231.                 cut_path(pathname);
  232.                 strcat(pathname,filename); /* zugriffspfad zusammensetzen */
  233.                 wind_update(END_MCTRL); /* wg, graf_slidebox() lt. Profibuch S.691 */
  234.                 wind_update(END_UPDATE);
  235.                 return(TRUE);
  236.             }
  237.         }
  238.     }
  239.     else
  240.     {
  241. #endif
  242. #if MSDOS
  243.         if(gb.gb_pglobal[0]<0x0400)     /* bei GEM/3 */
  244.             fselbox->ob_width=476;
  245.         else
  246.             fselbox->ob_width=476+28;      /* bei GEM/4 */
  247.         fselbox[FSELTEXT].ob_x=
  248.             (fselbox[ROOT].ob_width-fselbox[FSELTEXT].ob_spec.tedinfo->te_txtlen*8)/2;
  249. #endif
  250.         form_center(fselbox,&i,&i,&i,&i);
  251. #if GEMDOS
  252.         fselbox->ob_y=ydesk+7;
  253.         fselbox->ob_state&=~SHADOWED; /* Atari-like */
  254.         fselbox->ob_state|=OUTLINED;
  255. #else
  256.         fselbox->ob_y=2*ydesk;
  257.         fselbox->ob_spec.obspec.framesize=1; /* eigentlich framesize,...    */
  258.                                                     /* aber anscheinend vertauscht */
  259.         fselbox->ob_state|=SHADOWED;
  260.         fselbox->ob_state&=~OUTLINED;
  261. #endif
  262.         form_write(fselbox,FSELTEXT,meldung,FALSE);
  263.         form_open(fselbox,0);
  264.         if(fsel_input(pathname,filename,&button))
  265.         {
  266.             if(button && strlen(filename))
  267.             {
  268.                 cut_path(pathname);
  269.                 strcat(pathname,filename); /* zugriffspfad zusammensetzen */
  270.                 form_close(fselbox,-1,0);
  271.                 wind_update(END_MCTRL); /* wg, graf_slidebox() lt. Profibuch S.691 */
  272.                 wind_update(END_UPDATE);
  273.                 return(TRUE);
  274.             }
  275.         }
  276.         form_close(fselbox,-1,0);
  277. #if GEMDOS
  278.     }
  279. #endif
  280.     wind_update(END_MCTRL); /* wg, graf_slidebox() lt. Profibuch S.691 */
  281.     wind_update(END_UPDATE);
  282.     return(FALSE);
  283. }
  284.  
  285. int getfilename(char *pathname, char *pattern, char *fname, const char *meldung)
  286. {
  287.     int i,button;
  288.     static int first=TRUE;
  289.     static char path[PATH_MAX],filename[FILENAME_MAX];
  290.     char *cp;
  291.     WINDOW *wp;
  292.  
  293. #if GEMDOS
  294.     if(first)
  295.     {
  296.         filename[0]=0;
  297.         path[0]=(char)(Dgetdrv()+'A');
  298.         path[1]=':';
  299.         Dgetpath(&path[2],0);
  300.         strcat(path,"\\");
  301.         if(*pattern)
  302.             strcat(path,pattern);
  303.         else
  304.             strcat(path,"*.*");
  305.         first=FALSE;
  306.     }
  307. #else
  308.     if(first)
  309.     {
  310.         filename[0]=0;
  311.         path[0]=(char)(getdisk()+'A');
  312.         path[1]=':';
  313.         path[2]='\\';
  314.         getcurdir(0,&path[3]);
  315.         complete_path(path);
  316.         if(*pattern)
  317.             strcat(path,pattern);
  318.         else
  319.             strcat(path,"*.*");
  320.         first=FALSE;
  321.     }
  322. #endif
  323.  
  324.     if(!first)
  325.     {
  326.         if(*pattern)
  327.         {
  328.             cut_path(path);
  329.             strcat(path,pattern);
  330.         }
  331.         switch(*fname)
  332.         {
  333.             case '@':
  334.                 *filename=0;
  335.                 break;
  336.             case '\0':
  337.                 break;
  338.             default:
  339.                 strcpy(filename,fname);
  340.                 break;
  341.         }
  342.     }
  343.  
  344.     if(*pathname)
  345.         strcpy(path,pathname);
  346.     else
  347.     {
  348.         if((divmenu[DIVPATH].ob_state&SELECTED) &&  /* wenn angeklickt... */
  349.             ((wp=Wgettop())!=NULL) &&                    /* und Fenster offen... */
  350.             (strchr(wp->name,':')))                     /* und vollständig...    */
  351.         {                                                        /* dann Pfad übernehmen */
  352.             strcpy(path,(char *)Wname(wp));
  353.             cut_path(path);
  354.             strcat(path,"*");
  355.             if(cp=strrchr(wp->name,'.')) /* letzter Punkt von hinten */
  356.                 strcat(path,cp);
  357.             else
  358.                 strcat(path,".*");
  359.             *filename=0;
  360.         }
  361.     }
  362.     wind_update(BEG_UPDATE);
  363.     wind_update(BEG_MCTRL); /* wg, graf_slidebox() lt. Profibuch S.691 */
  364. #if GEMDOS
  365.  
  366.     if(_GemParBlk.global[0] >= 0x0140 || get_cookie('FSEL'))
  367.     {
  368.         if(fsel_exinput(path,filename,&button,meldung))
  369.         {
  370.             if(button && strlen(filename))
  371.             {
  372.                 strcpy(pathname,path);
  373.                 if((cp=strrchr(pathname,'\\'))!=NULL || (cp=strrchr(pathname,'/'))!=NULL) /* Extender merken */
  374.                     strcpy(pattern,cp+1);
  375.                 cut_path(pathname);
  376.                 strcat(pathname,filename); /* zugriffspfad zusammensetzen */
  377.                 wind_update(END_MCTRL); /* wg, graf_slidebox() lt. Profibuch S.691 */
  378.                 wind_update(END_UPDATE);
  379.                 return(TRUE);
  380.             }
  381.         }
  382.     }
  383.     else
  384.     {
  385. #endif
  386. #if MSDOS
  387.         if(gb.gb_pglobal[0]<0x0400)     /* bei GEM/3 */
  388.             fselbox->ob_width=476;
  389.         else
  390.             fselbox->ob_width=476+28;      /* bei GEM/4 */
  391.         fselbox[FSELTEXT].ob_x=
  392.             (fselbox[ROOT].ob_width-fselbox[FSELTEXT].ob_spec.tedinfo->te_txtlen*8)/2;
  393. #endif
  394.         form_center(fselbox,&i,&i,&i,&i);
  395. #if GEMDOS
  396.         fselbox->ob_y=ydesk+7;
  397.         fselbox->ob_state&=~SHADOWED; /* Atari-like */
  398.         fselbox->ob_state|=OUTLINED;
  399. #else
  400.         fselbox->ob_y=2*ydesk;
  401.         fselbox->ob_spec.obspec.framesize=1; /* eigentlich framesize,...    */
  402.                                                     /* aber anscheinend vertauscht */
  403.         fselbox->ob_state|=SHADOWED;
  404.         fselbox->ob_state&=~OUTLINED;
  405. #endif
  406.         form_write(fselbox,FSELTEXT,meldung,FALSE);
  407.         form_open(fselbox,0);
  408.         if(fsel_input(path,filename,&button))
  409.         {
  410.             if(button && strlen(filename))
  411.             {
  412.                 strcpy(pathname,path);
  413.                 if((cp=strrchr(pathname,'\\'))!=NULL || (cp=strrchr(pathname,'/'))!=NULL) /* Extender merken */
  414.                     strcpy(pattern,cp+1);
  415.                 cut_path(pathname);
  416.                 strcat(pathname,filename); /* zugriffspfad zusammensetzen */
  417.                 form_close(fselbox,-1,0);
  418.                 wind_update(END_MCTRL); /* wg, graf_slidebox() lt. Profibuch S.691 */
  419.                 wind_update(END_UPDATE);
  420.                 return(TRUE);
  421.             }
  422.         }
  423.         form_close(fselbox,-1,0);
  424. #if GEMDOS
  425.     }
  426. #endif
  427.     if((cp=strrchr(path,'\\'))!=NULL || (cp=strrchr(pathname,'/'))!=NULL)  /* Extender in jedem Falle merken */
  428.         strcpy(pattern,cp+1);
  429.     wind_update(END_MCTRL); /* wg, graf_slidebox() lt. Profibuch S.691 */
  430.     wind_update(END_UPDATE);
  431.     return(FALSE);
  432. }
  433.  
  434. char *split_fname(char *pathname)
  435. {
  436.     register char *cp;
  437. /*
  438.     if(getenv("UNIXMODE")!=NULL)
  439.     {
  440.         if((cp=strrchr(pathname,'/'))!=NULL)
  441.             return(cp+1);
  442.         else
  443.             return(pathname);
  444.     }
  445.     else
  446. */
  447.     {
  448.         if((cp=strrchr(pathname,'\\'))!=NULL)
  449.             return(cp+1);
  450.         if((cp=strrchr(pathname,'/'))!=NULL)
  451.             return(cp+1);
  452.         return(pathname);
  453.     }
  454. }
  455.  
  456. long strcchg(register char *str, register char old, register char new)
  457. {
  458.    register long count=0;
  459.     do
  460.     {
  461.         if(*str==old)
  462.         {
  463.             *str=new;
  464.             count++;
  465.         }
  466.     }
  467.     while(*(++str));
  468.    return(count);
  469. }
  470.  
  471. int isascformat(char *name)
  472. {
  473.     register int k;
  474.     k=strlen(name);
  475.     if(toupper(name[k-3])=='A' &&  /*  *.ASC laden */
  476.         toupper(name[k-2])=='S' &&
  477.         toupper(name[k-1])=='C')
  478.         return(TRUE);
  479.     return(FALSE);
  480. }
  481.  
  482. int read_file(WINDOW *wp,char *name)
  483. {
  484.     FILE *fp;
  485.     long k=0;
  486.     char filename[PATH_MAX],lastchar=0;
  487.     int ascformat=FALSE,blank,enough_ram=TRUE;
  488.     register LINESTRUCT *line,*help;
  489.     static char fpattern[FILENAME_MAX]="*.*";
  490.  
  491. #if GEMDOS
  492.     int buff[2048];
  493. #endif
  494.     if(name)
  495.         strcpy(filename,name);
  496.     else
  497.     {
  498.         filename[0]=0;
  499.         if(!getfilename(filename,fpattern,"",fselmsg[10]))
  500.         {
  501.             wp->name[0]=0;
  502.             return(FALSE);
  503.         }
  504.         wp->hfirst=wp->wfirst=0;
  505.         wp->row=wp->col=0;
  506.     }
  507.     wp->draw=Wtxtdraw;
  508.     Wnewname(wp,filename);
  509.  
  510.     ascformat=isascformat(wp->name); /* Extension .ASC? */
  511.     k=0;
  512.     if((fp=fopen(filename,"rb"))!=NULL)
  513.     {
  514.         wp->umbruch--;
  515.         graf_mouse(BUSY_BEE,NULL);
  516.         if(filelength(fileno(fp))==0)
  517.         {
  518.             graf_mouse(M_OFF,NULL);
  519.             Wcursor(wp);
  520.             ins_line(wp);
  521.             Wcursor(wp);
  522.             graf_mouse(M_ON,NULL);
  523.             k=1;
  524.         }
  525.         else
  526.         {
  527. /*
  528.             fseek(fp,-4L,SEEK_END);                    /* vier Bytes vor das Ende */
  529.             fread(buff,1L,4L,fp);                      /* vier Bytes lesen */
  530.             if(!strncmp(buff,"\r\t\r\t",4))         /* CR TAB CR TAB */
  531.             {
  532.                 wp->tab=0;
  533.                 fseek(fp,-(wp->tab+1+4L),SEEK_END);  /* ab Stelle davor Anzahl Tabs */
  534.                 while(fgetc(fp)=='\t')                    /* lesen und zurückrücken */
  535.                 {
  536.                     fseek(fp,-(++wp->tab+1+4L),SEEK_END); /* nochmal zurück und lesen */
  537.                 }
  538.                 if(wp->tab==0)
  539.                     wp->tab=1;
  540.             }
  541. */
  542. #if GEMDOS
  543.             if(setvbuf(fp,NULL,_IOFBF,FILEIOBUFF))
  544.                 setvbuf(fp,buff,_IOFBF,sizeof(buff));
  545. #endif
  546.             if((line=malloc(sizeof(LINESTRUCT)))!=NULL)
  547.             {
  548.                 wp->cstr=wp->wstr=wp->fstr=line;
  549.                 wp->cstr->prev=wp->wstr->prev=wp->fstr->prev=line->prev=NULL;
  550.                 while((enough_ram != -1) && (fgets(iostr2,ascformat?wp->umbruch+2:STRING_LENGTH+2, fp) != NULL))
  551.                 {
  552.                     if(ascformat) /* evtl. Zeilenumbruch */
  553.                     {
  554.                         iostr2[wp->umbruch+2]=0;
  555.                         line->len=strlen(iostr2);
  556.                         while((iostr2[line->len-1] == '\n') || 
  557.                               (iostr2[line->len-1] == '\r'))
  558.                         {
  559.                             iostr2[line->len-1]=0;
  560.                             line->len--;
  561.                         }
  562. /*
  563.                         if(iostr2[line->len-1] == '\n')
  564.                         {
  565.                             iostr2[line->len-1]=0;
  566.                             line->len--;
  567.                         }
  568.                         if(iostr2[line->len-1] == '\r')
  569.                         {
  570.                             iostr2[line->len-1]=0;
  571.                             line->len--;
  572.                         }
  573. */
  574.                         if(iostr2[0]==' ')
  575.                         {
  576.                             strcpy(iostr2,&iostr2[1]);
  577.                             line->len--;
  578.                         }
  579.                         if(line->len > wp->umbruch)
  580.                         {
  581.                             blank=findlastspace(iostr2,wp->umbruch,wp->umbruch+1);
  582.                             if(blank>0)
  583.                             {
  584.                                 fseek(fp,-(long)(wp->umbruch-blank),SEEK_CUR); /* zurück positionieren */
  585.                                 iostr2[blank]=0;
  586.                                 if(wp->w_state & BLOCKSATZ) /* evtl. Blocksatz formatieren */
  587.                                 {
  588.                                     blockformat(iostr2, wp->umbruch-blank);
  589.                                 }
  590.                             }
  591.                         }
  592.                         strcpy(iostring, iostr2);
  593.                         line->len=strlen(iostring);
  594.                     }
  595.                     else
  596.                     {
  597.                         if(tabexp)
  598.                             stpexpan(iostring, iostr2, wp->tab, STRING_LENGTH, &line->len);
  599.                         else
  600.                         {
  601.                             strcpy(iostring, iostr2);
  602.                             line->len=strlen(iostring);
  603.                         }
  604.                         lastchar=0;
  605.                         while((iostring[line->len-1] == '\n') || 
  606.                               (iostring[line->len-1] == '\r'))
  607.                         {
  608.                             iostring[line->len-1]=0;
  609.                             lastchar='\n';
  610.                             line->len--;
  611.                         }
  612. /*
  613.                         if(iostring[line->len-1] == '\n') /* Linefeed */
  614.                         {
  615.                             iostring[line->len-1]=0;
  616.                             lastchar='\n';
  617.                             line->len--;
  618.                         }
  619.                         if(iostring[line->len-1] == '\r') /* Carriage Return */
  620.                         {
  621.                             iostring[line->len-1]=0;
  622.                             lastchar='\r';
  623.                             line->len--;
  624.                         }
  625. */
  626.                     }
  627.                     if((line->string=malloc(line->len + 1))!=NULL)
  628.                     {
  629.                         k++;
  630.                         line->used = line->len;
  631.                         strcpy(line->string,iostring);
  632.                         if(eszet)
  633.                             strcchg(line->string,'β','β'); /* Peseta gegen IBM-Eszet         */
  634.                         line->attr=0;    /* zeilenmarkierung */
  635.                         line->effect=0; /* Texteffect */
  636. /*
  637.                         if(strchr(line->string,9))
  638.                             line->attr|=TABCOMP;
  639. */
  640.                         help=line;
  641.                         if((line->next=malloc(sizeof(LINESTRUCT))) != NULL)
  642.                         {
  643.                             line=line->next;
  644.                             line->prev=help;
  645.                             line->next=NULL;
  646.                         }
  647.                         else
  648.                         {
  649.                             enough_ram=-1;
  650.                             lastchar=0; /* OUT OF MEMORY überlisten */
  651.                             goto WEITER;
  652.                         }
  653.                     }
  654.                     else
  655.                     {
  656.                         enough_ram=-1;
  657.                         lastchar=0;
  658.                     }
  659.                 }
  660.                 if((lastchar!=0) && ((line->string=malloc(NBLOCKS+1))!=NULL))
  661.                 {
  662.                     line->string[0]=0;
  663.                     line->len=NBLOCKS;
  664.                     line->used=0;
  665.                     line->attr=0;
  666.                     line->effect=0; /* Texteffect */
  667.                     line->next=NULL;
  668.                     k++;
  669.                 }
  670.                 else
  671.                 {
  672.                     line=line->prev;
  673.                     free(line->next);
  674.                     line->next=NULL;
  675.                 }
  676. WEITER:     ;
  677.             }
  678.             else
  679.                 enough_ram=-1;
  680.         }
  681.         fclose(fp);
  682.         wp->hsize = k * wp->hscroll;
  683.         graf_mouse(ARROW,NULL);
  684.         wp->umbruch++;
  685.     }
  686.     else
  687.     {
  688.         return(FALSE);
  689.     }
  690.     return(enough_ram);
  691. }
  692.  
  693. int _read_blk(WINDOW *wp, char *filename, LINESTRUCT **begcut, LINESTRUCT **endcut)
  694. {
  695.     FILE *fp;
  696.     register long k=0;
  697.     int ascformat=FALSE,blank, enough_ram=TRUE;
  698.     register LINESTRUCT *line, *help1;
  699.     char lastchar=0;
  700.  
  701. #if GEMDOS
  702.     int buff[2048];
  703. #endif
  704.  
  705.     ascformat=isascformat(wp->name); /* Extension .ASC? */
  706.     k=0;
  707.     if((fp=fopen(filename,"rb")) != NULL)
  708.     {
  709.         wp->umbruch--;
  710.         graf_mouse(BUSY_BEE,NULL);
  711.         if(filelength(fileno(fp))==0)
  712.         {
  713.             enough_ram=FALSE;
  714.         }
  715.         else
  716.         {
  717. #if GEMDOS
  718.             if(setvbuf(fp,NULL,_IOFBF,FILEIOBUFF))
  719.                 setvbuf(fp,buff,_IOFBF,sizeof(buff));
  720. #endif
  721.             if((line=malloc(sizeof(LINESTRUCT)))!=NULL)
  722.             {
  723.                 (*begcut)=line;
  724.                 begline=begline=wp->row+wp->hfirst/wp->hscroll;  /* zeilen = 1 */
  725.                 line->prev=NULL;
  726.                 while((enough_ram != -1) && (fgets(iostr2,ascformat?wp->umbruch+2:STRING_LENGTH+2, fp) != NULL))
  727.                 {
  728.                     if(ascformat) /* evtl. Zeilenumbruch */
  729.                     {
  730.                         iostr2[wp->umbruch+2]=0;
  731.                         line->len=strlen(iostr2);
  732.                         while((iostr2[line->len-1] == '\n') || 
  733.                               (iostr2[line->len-1] == '\r'))
  734.                         {
  735.                             iostr2[line->len-1]=0;
  736.                             line->len--;
  737.                         }
  738. /*
  739.                         if(iostr2[line->len-1] == '\n')
  740.                         {
  741.                             iostr2[line->len-1]=0;
  742.                             line->len--;
  743.                         }
  744.                         if(iostr2[line->len-1] == '\r')
  745.                         {
  746.                             iostr2[line->len-1]=0;
  747.                             line->len--;
  748.                         }
  749. */
  750.                         if(iostr2[0]==' ')
  751.                         {
  752.                             strcpy(iostr2,&iostr2[1]);
  753.                             line->len--;
  754.                         }
  755.                         if(line->len > wp->umbruch)
  756.                         {
  757.                             blank=findlastspace(iostr2,wp->umbruch,wp->umbruch+1);
  758.                             if(blank>0)
  759.                             {
  760.                                 fseek(fp,-(long)(wp->umbruch-blank),SEEK_CUR); /* zurück positionieren */
  761.                                 iostr2[blank]=0;
  762.                                 if(wp->w_state & BLOCKSATZ) /* evtl. Blocksatz formatieren */
  763.                                 {
  764.                                     blockformat(iostr2, wp->umbruch-blank);
  765.                                 }
  766.                             }
  767.                         }
  768.                         strcpy(iostring, iostr2);
  769.                         line->len=strlen(iostring);
  770.                     }
  771.                     else
  772.                     {
  773.                         if(tabexp)
  774.                             stpexpan(iostring, iostr2, wp->tab, STRING_LENGTH,&line->len);
  775.                         else
  776.                         {
  777.                             strcpy(iostring, iostr2);
  778.                             line->len=strlen(iostring);
  779.                         }
  780.                         lastchar=0;
  781.                         while((iostring[line->len-1] == '\n') || 
  782.                               (iostring[line->len-1] == '\r'))
  783.                         {
  784.                             iostring[line->len-1]=0;
  785.                             lastchar='\n';
  786.                             line->len--;
  787.                         }
  788. /*
  789.                         if(iostring[line->len-1] == '\n')
  790.                         {
  791.                             iostring[line->len-1]=0;
  792.                             lastchar='\n';
  793.                             line->len--;
  794.                         }
  795.                         if(iostring[line->len-1] == '\r') /* Carriage Return */
  796.                         {
  797.                             iostring[line->len-1]=0;
  798.                             lastchar='\r';
  799.                             line->len--;
  800.                         }
  801. */
  802.                     }
  803.  
  804.                     if((line->string=malloc(line->len + 1)) != NULL)
  805.                     {
  806.                         k++;
  807.                         line->used = line->len;
  808.                         strcpy(line->string,iostring);
  809.  
  810.                         if(eszet)
  811.                             strcchg(line->string,'β','β'); /* Peseta gegen IBM-Eszet         */
  812.                         line->attr=0;    /* zeilenmarkierung */
  813.                         line->effect=0; /* Texteffect */
  814. /*
  815.                         if(strchr(line->string,9))
  816.                             line->attr|=TABCOMP;
  817. */
  818.                         help1=line;
  819.                         if((line->next=malloc(sizeof(LINESTRUCT))) != NULL)
  820.                         {
  821.                             line=line->next;
  822.                             line->prev=help1;
  823.                             line->next=NULL;
  824.                         }
  825.                         else
  826.                         {
  827.                             enough_ram=-1;
  828.                             lastchar=0;
  829.                             goto WEITER;
  830.                         }
  831.                     }
  832.                     else
  833.                     {
  834.                         enough_ram=-1;
  835.                         lastchar=0;
  836.                     }
  837.                 }
  838.                 if((lastchar!=0) && ((line->string=malloc(NBLOCKS+1))!=NULL))
  839.                 {
  840.                     line->string[0]=0;
  841.                     line->len=NBLOCKS;
  842.                     line->used=0;
  843.                     line->attr=0;
  844.                     line->effect=0; /* Texteffect */
  845.                     line->next=NULL;
  846.                     k++;
  847.                 }
  848.                 else
  849.                 {
  850.                     line=line->prev;
  851.                     free(line->next);
  852.                     line->next=NULL;
  853.                 }
  854. WEITER:
  855.                 (*endcut)=line;                             /* ende markieren */
  856.                 endline=begline + k;
  857.             }
  858.             else
  859.                 enough_ram=-1;
  860.         }
  861.         fclose(fp);
  862.         graf_mouse(ARROW,NULL);
  863.         wp->umbruch++;
  864.         return(enough_ram);
  865.     }
  866.     return(FALSE);
  867. }
  868.  
  869. int read_clip(WINDOW *wp, LINESTRUCT **begcut, LINESTRUCT **endcut)
  870. {
  871.     char filename[PATH_MAX];
  872.  
  873.     if(wp)
  874.     {
  875.         scrp_read(filename);
  876.         if(!*filename)
  877.         {
  878.             form_alert(1,Afileio[3]);
  879.             return(FALSE);
  880.         }
  881.         complete_path(filename);
  882.         strcat(filename,"SCRAP.TXT");
  883.  
  884.         switch(_read_blk(wp, filename,begcut,endcut))
  885.         {
  886.             case -1:
  887.                 form_alert(1,Afileio[4]);
  888.             case TRUE:
  889.                 wp->w_state|=CHANGED;
  890.                 return(TRUE);
  891.             case FALSE:
  892.                 form_alert(1,Afileio[5]);
  893.                 break;
  894.         }
  895.     }
  896.     return(FALSE);
  897. }
  898.  
  899. WINDOW *Wnewfile(char *name)
  900. {
  901.     WINDOW *wp=NULL;
  902.     char *cp, pathname[PATH_MAX],filename[FILENAME_MAX];
  903.     int wort1, ret;
  904. /*    
  905.    WI_KIND &= ~SMALLER;
  906.     if(_GemParBlk.global[0]>=0x0399)
  907.     {
  908.        appl_getinfo(12, &wort1, &ret, &ret, &ret);
  909.        if((wort1 & 0x0080) && (wort1 & 0x0100))
  910.          WI_KIND |= SMALLER;
  911.     }
  912. */
  913.     if(wp=Wcreate(WI_KIND,xdesk,ydesk,wdesk,hdesk))
  914.     {
  915.         Wdefattr(wp);
  916.         wp->hsize=0;
  917.         wp->wsize =STRING_LENGTH*wp->wscroll;
  918.         if((wp->name=malloc(max(PATH_MAX,strlen(name)+1+12)))==NULL)
  919.         {
  920.             Wdelete(wp);
  921.             return(NULL);
  922.         }
  923.         wp->name[0]=0;
  924.         if((wp->info=malloc(80))==NULL)
  925.         {
  926.             free(wp->name);
  927.             Wdelete(wp);
  928.             return(NULL);
  929.         }
  930.         wp->info[0]=0;
  931.  
  932.         Wnewname(wp,name);
  933.         Wnewinfo(wp,"");
  934.         wp->draw=Wtxtdraw;
  935.         wp->type=TEXT;
  936.         add_icon(desktop, wp->icon);
  937.         ren_icon(desktop, wp->icon);
  938.         wp->hfirst=wp->wfirst=0;
  939.         wp->row=wp->col=wp->cspos=0;
  940.         ins_line(wp);
  941.         Wsetscreen(wp);
  942.         Wsetrcinfo(wp);
  943.         if(!Wopen(wp))
  944.         {
  945.             form_alert(1,Afileio[6]);
  946.             _exit(-1);
  947.         }
  948.         Wcuron(wp);
  949.         strcpy(filename,split_fname((char *)Wname(wp)));
  950.         change_linealname(filename,"LINEAL");
  951.         search_env(pathname,filename,FALSE); /* READ */
  952.         _read_lin(wp,pathname);
  953.  
  954.         wp->cspos=0;
  955.         undo.menu=WINFILE;
  956.         undo.item=WINCLOSE;
  957.     }
  958.     else
  959.         form_alert(1,Afileio[7]);
  960.     return(wp);
  961. }
  962.  
  963. WINDOW *Wreadfile(char *name, int automatic)
  964. {
  965.     WINDOW *wp=NULL;
  966.     char *cp,pathname[PATH_MAX],filename[FILENAME_MAX];
  967.     int wort1, ret;
  968. /*    
  969.    WI_KIND &= ~SMALLER;
  970.     if(_GemParBlk.global[0]>=0x0399)
  971.     {
  972.        appl_getinfo(12, &wort1, &ret, &ret, &ret);
  973.        if((wort1 & 0x0080) && (wort1 & 0x0100))
  974.          WI_KIND |= SMALLER;
  975.     }
  976. */
  977.     if(wp=Wcreate(WI_KIND,xdesk,ydesk,wdesk,hdesk))
  978.     {
  979.         Wdefattr(wp);
  980.         wp->hsize=0;
  981.         wp->wsize =STRING_LENGTH*wp->wscroll;
  982.         if((wp->name=malloc(max(PATH_MAX,strlen(name)+1+12)))==NULL)
  983.         {
  984.             Wdelete(wp);
  985.             return(NULL);
  986.         }
  987.         wp->name[0]=0;
  988.         if((wp->info=malloc(80))==NULL)
  989.         {
  990.             free(wp->name);
  991.             Wdelete(wp);
  992.             return(NULL);
  993.         }
  994.         wp->info[0]=0;
  995.  
  996.         Wnewname(wp,NAMENLOS);
  997.         Wnewinfo(wp,"");
  998.         wp->type=TEXT;
  999.         wp->cspos=0;
  1000.         switch(read_file(wp,name))
  1001.         {
  1002.             case -1: /* kein ram frei */
  1003.                 sprintf(iostring,Afileio[1],split_fname((char *)Wname(wp)));
  1004.                 form_alert(1,iostring); /* kein break, es geht weiter */
  1005.             case TRUE: /* ok */
  1006.                 add_icon(desktop, wp->icon);
  1007.                 ren_icon(desktop, wp->icon);
  1008.                 if(!automatic)
  1009.                 {
  1010.                     wp->hfirst=wp->wfirst=0;
  1011.                     wp->row=wp->col=0;
  1012.                 }
  1013.                 Wsetrcinfo(wp);
  1014.                 Wsetscreen(wp);
  1015.                 if(!Wopen(wp))
  1016.                 {
  1017.                     form_alert(1,Afileio[6]);
  1018.                     _exit(-1);
  1019.                 }
  1020.                 Wslupdate(wp,1+2+4+8);
  1021.                 Wcuron(wp);
  1022.                 strcpy(filename,split_fname((char *)Wname(wp)));
  1023.                 change_linealname(filename,"LINEAL");
  1024.                 search_env(pathname,filename,FALSE); /* READ */
  1025.                 _read_lin(wp,pathname);
  1026.                 undo.menu=WINFILE;
  1027.                 undo.item=WINCLOSE;
  1028.                 break;
  1029.             case FALSE: /* keine Datei gewählt */
  1030.                 strcpy(iostring,(char *)Wname(wp));
  1031.                 Wdelete(wp);
  1032.                 if(*iostring)
  1033.                 {
  1034.                     sprintf(alertstr,Afileio[8],(char *)split_fname(iostring));
  1035.                     if(form_alert(2,alertstr)==2)
  1036.                         wp=Wnewfile(iostring);
  1037.                     else
  1038.                         wp=NULL;
  1039.                 }
  1040.                 break;
  1041.         }
  1042.     }
  1043.     else
  1044.         form_alert(1,Afileio[7]);
  1045.     return(wp);
  1046. }
  1047.  
  1048. WINDOW *Wgetwp(char *filename);
  1049.  
  1050. WINDOW *Wreadtempfile(char *filename, int mode)
  1051. {
  1052.     FILE *fp;
  1053.     WINDOW *wp=NULL;
  1054.     char tempname[PATH_MAX];
  1055.  
  1056.     if(wp=Wgetwp(filename))  /* schon geladen ? */
  1057.     {
  1058.         if(!(wp->w_state & OPENED))
  1059.             Wopen(wp);             /* als Icon, also öffnen */
  1060.         else
  1061.             Wtop(wp);             /* nur toppen */
  1062.         return(wp);
  1063.     }
  1064.     else
  1065.     {
  1066.         strcpy(tempname,filename);
  1067.         change_ext(tempname,".$$$");
  1068. /*
  1069.         if((fp=fopen(tempname,"r"))!=NULL)
  1070.         {
  1071.             fclose(fp);
  1072. */
  1073.         if(access(tempname,0))
  1074.         {
  1075.             sprintf(alertstr,Afileio[10],split_fname(filename));
  1076.             if(form_alert(2,alertstr)==2)
  1077.             {
  1078.                 if(wp=Wreadfile(tempname,mode))
  1079.                 {
  1080.                     Wnewname(wp,filename);
  1081.                     ren_icon(desktop, wp->icon);
  1082.                     return(wp);
  1083.                 }
  1084.             }
  1085.         }
  1086.         return(Wreadfile(filename,mode));
  1087.     }
  1088. }
  1089.  
  1090. static char *colcpy(char *str, LINESTRUCT *line) /* Spalte herauskopieren */
  1091. {
  1092.     if(line->begcol < line->used)
  1093.     {
  1094.         strcpy(str,&line->string[line->begcol]);
  1095.         str[line->endcol-line->begcol]=0;
  1096.         blank(str,line->endcol-line->begcol);/* evtl. blanks */
  1097.     }
  1098.     else /* auβerhalb des strings > line->used */
  1099.     {
  1100.         memset(str,' ',line->endcol-line->begcol);
  1101.         str[line->endcol-line->begcol]=0;
  1102.     }
  1103.     return(str);
  1104. }
  1105.  
  1106. static int _write_blk(WINDOW *wp, char *filename, LINESTRUCT *beg, LINESTRUCT *end)
  1107. {
  1108.     FILE *fp;
  1109.     register LINESTRUCT *line;
  1110.     char openmodus[2];
  1111.     int error,ret,kstate;
  1112.  
  1113. #if GEMDOS
  1114.     int buff[2048];
  1115. #endif
  1116.  
  1117.     graf_mkstate(&ret,&ret,&ret,&kstate);
  1118.     if(kstate & (K_LSHIFT|K_RSHIFT))     /* bei gedrückter Shifttaste... */
  1119.         strcpy(openmodus,"a");              /* ans Clipboard anhängen,...*/
  1120.     else
  1121.         strcpy(openmodus,"w");                /* ...sonst neue Datei      */
  1122.  
  1123.     if((fp=fopen(filename,openmodus))!=NULL)
  1124.     {
  1125.         graf_mouse(BUSY_BEE,NULL);
  1126. #if GEMDOS
  1127.         if(setvbuf(fp,NULL,_IOFBF,FILEIOBUFF))
  1128.             setvbuf(fp,buff,_IOFBF,sizeof(buff));
  1129. #endif
  1130.         line=beg;
  1131.         do
  1132.         {
  1133.             if((wp->w_state&COLUMN)) /* bei Spaltenblock */
  1134.             {
  1135.                 if(fputs(colcpy(iostring,line),fp)==EOF)
  1136.                 {
  1137.                     form_alert(1,Afileio[11]);
  1138.                     goto WEITER;
  1139.                 }
  1140.             }
  1141.             else
  1142.             {
  1143.                 strcpy(iostring,&line->string[line->begcol]);
  1144.                 iostring[line->endcol-line->begcol]=0;
  1145.                 if(fputs(iostring,fp)==EOF)
  1146.                 {
  1147.                     form_alert(1,Afileio[11]);
  1148.                     goto WEITER;
  1149.                 }
  1150.             }
  1151.             if(line->next != end->next)
  1152.             {
  1153.                 if(fputs("\n",fp)==EOF)
  1154.                 {
  1155.                     form_alert(1,Afileio[11]);
  1156.                     goto WEITER;
  1157.                 }
  1158.             }
  1159.             else
  1160.             {
  1161.                 if(line->endcol==STRING_LENGTH)
  1162.                 {
  1163.                     if(fputs("\n",fp)==EOF)
  1164.                     {
  1165.                         form_alert(1,Afileio[11]);
  1166.                         goto WEITER;
  1167.                     }
  1168.                 }
  1169.             }
  1170.             line=line->next;
  1171.         }
  1172.         while(line != end->next);
  1173. WEITER:
  1174.         error=ferror(fp);
  1175.         fclose(fp);
  1176.         if(error)
  1177.             unlink(filename);
  1178.         graf_mouse(ARROW,NULL);
  1179.         return(TRUE);
  1180.     }
  1181.     return(FALSE);
  1182. }
  1183.  
  1184. char *change_ext(char *name, char *ext)
  1185. {
  1186.     char *cp;
  1187.  
  1188.     cp=strrchr(name,'.');
  1189.     if(cp)
  1190.         *cp=0;
  1191.     strcat(name,ext);
  1192.     return(name);
  1193. }
  1194.  
  1195. char *change_name(char *name, char *newname)
  1196. {
  1197.     register int i,k;
  1198.     char *cp,temp[PATH_MAX];
  1199.  
  1200.     cp=split_fname(name);
  1201.     strcpy(temp,cp);
  1202.     *cp=0;
  1203.     strcat(name,newname);
  1204.     k=strlen(temp);
  1205.     for(i=0; i<k; i++)
  1206.         if(temp[i]=='.')
  1207.             break;
  1208.     if(temp[i]=='.')
  1209.         strcat(name,&temp[i]);
  1210.     return(name);
  1211. }
  1212.  
  1213. char *change_linealname(char *name, char *newname)
  1214. {
  1215.     register int i,k;
  1216.     char *cp,temp[PATH_MAX];
  1217. /*
  1218.     cp=split_fname(name);
  1219.     strcpy(temp,cp);
  1220.     *cp=0;
  1221.     strcat(name,newname);
  1222.     k=strlen(temp);
  1223.     for(i=0; i<k; i++)
  1224.         if(temp[i]=='.')
  1225.             break;
  1226.     if(temp[i]=='.')
  1227.         strcat(name,&temp[i]);
  1228.     return(name);
  1229. */
  1230.     strcpy(temp,name);
  1231.     if((cp=strrchr(temp,'\\'))!=NULL || (cp=strrchr(temp,'/'))!=NULL)
  1232.         cp[1]=0;
  1233.     else
  1234.         temp[0]=0;
  1235.         
  1236.     strcat(temp,"7UP");
  1237.     cp=strrchr(name,'.');
  1238.     if(cp)
  1239.         strcat(temp,&cp[1]);
  1240.  
  1241.     strcat(temp,".LIN");
  1242.     strcpy(name,temp);
  1243.     return(name);
  1244. }
  1245.  
  1246. /*
  1247. static long bwrite(WINDOW *wp, LINESTRUCT *line, int ascformat, FILE *fp)
  1248. {
  1249.     char *save=NULL, *buff=NULL, *cp;
  1250.     long count=0,m,n,bsize,lines,chars;
  1251.  
  1252. #if GEMDOS
  1253.     Wtxtsize(wp,&lines,&chars);
  1254.     bsize=(long)Malloc(-1L)-4096L;
  1255. #else
  1256.     bsize=farcoreleft()-4096L;
  1257. #endif
  1258.     if(bsize<0)
  1259.         return(0);
  1260.     if(wret)
  1261.        chars+=lines; /* für jede Zeile ein Blanks nicht vergessen */
  1262. #if GEMDOS
  1263.     save=buff=Malloc((long)min(chars+2,bsize+2));
  1264. #else
  1265.     save=buff=malloc(bsize=min(bsize,32000)+2);
  1266. #endif
  1267.     if(buff)
  1268.     {
  1269.         do
  1270.         {
  1271.             while(line && ((buff+line->used+3L) < (save+bsize)))
  1272.             {
  1273.                 if(bcancel && !ascformat)
  1274.                     if(line->used > 0)
  1275.                     {
  1276.                         while(line->string[--line->used] == ' ')
  1277.                             line->string[line->used] = 0;
  1278.                         line->used++;
  1279.                     }
  1280.                 strcpy(iostring,line->string);
  1281.                 if(ascformat)
  1282.                 {
  1283.                     cp=strchr(iostring,' ');
  1284.                     while(cp)
  1285.                     {
  1286.                         if(*(cp+1L) == ' ')
  1287.                             strcpy(cp,cp+1L);
  1288.                         cp=strchr((*(cp+1L)==' '?cp:cp+1L),' ');
  1289.                     }
  1290.                 }
  1291. /*
  1292.                 if(wp->w_state & TABCOMP)                    /* tab compression */
  1293.                     strcpy(buff,stptabfy(iostring, wp->tab));
  1294.                 else
  1295. */
  1296.                     strcpy(buff,iostring);
  1297.                 buff+=strlen(buff);
  1298.                 if(line->next)
  1299.                 {
  1300.                     if(ascformat)
  1301.                     {                                                            /* ASC-Format */
  1302.                         if(!line->next->used || !line->used)          /* Absatzende */
  1303.                         {
  1304.                             switch(lineendsign) /* Zeilenendekennung */
  1305.                             {
  1306.                                 case CRLF:
  1307.                                     strcat(buff,"\r\n");
  1308.                                     buff+=2L;
  1309.                                     break;
  1310.                                 case LF:
  1311.                                     strcat(buff,"\n");
  1312.                                     buff+=1L;
  1313.                                     break;
  1314.                                 case CR:
  1315.                                     strcat(buff,"\r");
  1316.                                     buff+=1L;
  1317.                                     break;
  1318.                             }
  1319.                         }
  1320.                         else
  1321.                         {
  1322.                             strcat(buff," "); /* Flieβtext */
  1323.                             buff+=1L;
  1324.                         }
  1325.                     }
  1326.                     else            /* TXT-Format */
  1327.                     {
  1328.                         if(wret)
  1329.                         {
  1330.                             if(line->next->used)
  1331.                             {                                    /* kein Blank bei Absatzende */
  1332.                                 strcat(buff," ");                        /* weiches Return */
  1333.                                 buff+=1L;
  1334.                             }
  1335.                         }
  1336.                         switch(lineendsign) /* Zeilenendekennung */
  1337.                         {
  1338.                             case CRLF:
  1339.                                 strcat(buff,"\r\n");
  1340.                                 buff+=2L;
  1341.                                 break;
  1342.                             case LF:
  1343.                                 strcat(buff,"\n");
  1344.                                 buff+=1L;
  1345.                                 break;
  1346.                             case CR:
  1347.                                 strcat(buff,"\r");
  1348.                                 buff+=1L;
  1349.                                 break;
  1350.                         }
  1351.                     }
  1352.                 }
  1353.                 line=line->next;
  1354.             }
  1355. #if GEMDOS
  1356.             n=Fwrite(fileno(fp),m=strlen(save),save);
  1357. #else
  1358.             n=_write(fileno(fp),save,m=strlen(save));
  1359. #endif
  1360.             if(n==m)
  1361.                 count+=n;
  1362.             else
  1363.             {
  1364.                 form_alert(1,Afileio[11]);
  1365.                 count=-1;
  1366.                 goto WEITER;
  1367.             }
  1368.             buff=save;
  1369.         }
  1370.         while(line);
  1371. WEITER:
  1372. #if GEMDOS
  1373.         Mfree(save);
  1374. #else
  1375.         free(save);
  1376. #endif
  1377.     }
  1378.     return(count);
  1379. }
  1380. */
  1381. void _write_file(WINDOW *wp, char *filename, char *openmodus, int newname, int ascformat, int signal)
  1382. {
  1383.     FILE *fp;
  1384.     register LINESTRUCT *line;
  1385.     char *cp;
  1386.     int i,error;
  1387.     struct ffblk fileRec;
  1388.     long lines,chars;
  1389.  
  1390. #if GEMDOS
  1391.     int buff[2048];
  1392. #endif
  1393.  
  1394.     if(wp)
  1395.     {
  1396.         if(signal==SIGNULL)
  1397.         {
  1398.             graf_mouse(M_OFF,NULL);
  1399.             Wcursor(wp);
  1400.             graf_mouse(M_ON,NULL);
  1401.         }
  1402. NOCHMAL:
  1403.         if((fp=fopen(filename,openmodus))!=NULL)
  1404.         {
  1405.             if(signal==SIGNULL)
  1406.                 graf_mouse(BUSY_BEE,NULL);
  1407.             line=wp->fstr;
  1408.             if(TRUE/*bwrite(wp,line,ascformat,fp)==0*/) /* schnell */
  1409.             {
  1410. #if GEMDOS
  1411.                 Wtxtsize(wp,&lines,&chars);
  1412.                 if(wret)
  1413.                    chars+=lines; /* für jede Zeile ein Blanks nicht vergessen */
  1414.  
  1415.                 if(setvbuf(fp,NULL,_IOFBF, ((chars/1024)+1)*1024 ))
  1416.                     if(setvbuf(fp,NULL,_IOFBF,FILEIOBUFF))
  1417.                         setvbuf(fp,buff,_IOFBF,sizeof(buff));
  1418. #endif
  1419.                 do
  1420.                 {                                         /* Blanks am Ende unterdrücken */
  1421.                     if(bcancel && !ascformat)
  1422.                         if(line->used > 0)
  1423.                         {
  1424.                             while(line->string[--line->used] == ' ')
  1425.                                 line->string[line->used] = 0;
  1426.                             line->used++;
  1427.                         }
  1428.                     strcpy(iostring,line->string);
  1429.                     if(ascformat)
  1430.                     {
  1431.                         cp=strchr(iostring,' ');
  1432.                         while(cp)
  1433.                         {
  1434.                             if(*(cp+1L) == ' ')
  1435.                                 strcpy(cp,cp+1L);
  1436.                             cp=strchr((*(cp+1L)==' '?cp:cp+1L),' ');
  1437.                         }
  1438.                     }
  1439.                     if(fputs(iostring,fp)==EOF)
  1440.                     {
  1441.                         form_alert(1,Afileio[11]);
  1442.                         goto WEITER;
  1443.                     }
  1444.                     if(line->next)
  1445.                     {
  1446.                         if(ascformat) /* ASC-Format */
  1447.                         {
  1448.                             if(!line->next->used || !line->used)
  1449.                             {
  1450.                                 switch(lineendsign) /* Zeilenendekennung */
  1451.                                 {
  1452.                                     case CRLF:
  1453.                                         if(fputs("\r\n",fp)==EOF)
  1454.                                         {
  1455.                                             form_alert(1,Afileio[11]);
  1456.                                             goto WEITER;
  1457.                                         }
  1458.                                         break;
  1459.                                     case LF:
  1460.                                         if(fputs("\n",fp)==EOF)
  1461.                                         {
  1462.                                             form_alert(1,Afileio[11]);
  1463.                                             goto WEITER;
  1464.                                         }
  1465.                                         break;
  1466.                                     case CR:
  1467.                                         if(fputs("\r",fp)==EOF)
  1468.                                         {
  1469.                                             form_alert(1,Afileio[11]);
  1470.                                             goto WEITER;
  1471.                                         }
  1472.                                         break;
  1473.                                 }
  1474.                             }
  1475.                             else
  1476.                             {
  1477.                                 if(fputs(" ",fp)==EOF)  /* weiches Return Absatzformat */
  1478.                                 {
  1479.                                     form_alert(1,Afileio[11]);
  1480.                                     goto WEITER;
  1481.                                 }
  1482.                             }
  1483.                         }
  1484.                         else
  1485.                         {
  1486.                             if(wret)
  1487.                             {
  1488.                                 if(fputs(" ",fp)==EOF)  /* weiches Return */
  1489.                                 {
  1490.                                     form_alert(1,Afileio[11]);
  1491.                                     goto WEITER;
  1492.                                 }
  1493.                             }
  1494.                             switch(lineendsign) /* Zeilenendekennung */
  1495.                             {
  1496.                                 case CRLF:
  1497.                                     if(fputs("\r\n",fp)==EOF)
  1498.                                     {
  1499.                                         form_alert(1,Afileio[11]);
  1500.                                         goto WEITER;
  1501.                                     }
  1502.                                     break;
  1503.                                 case LF:
  1504.                                     if(fputs("\n",fp)==EOF)
  1505.                                     {
  1506.                                         form_alert(1,Afileio[11]);
  1507.                                         goto WEITER;
  1508.                                     }
  1509.                                     break;
  1510.                                 case CR:
  1511.                                     if(fputs("\r",fp)==EOF)
  1512.                                     {
  1513.                                         form_alert(1,Afileio[11]);
  1514.                                         goto WEITER;
  1515.                                     }
  1516.                                     break;
  1517.                             }
  1518.                         }
  1519.                     }
  1520.                     line=line->next;
  1521.                 }
  1522.                 while(line);
  1523.             }
  1524. WEITER:
  1525.             error=ferror(fp);
  1526. /*
  1527.             for(i=0; i<wp->tab; i++)
  1528.                 fputc('\t',fp);
  1529.             fwrite("\r\t\r\t",1L,4L,fp);
  1530. */
  1531.             fclose(fp);
  1532.             if(error)
  1533.                 unlink(filename);
  1534.             else
  1535.             {
  1536. /*neu*/        if(newname && strcmp((char *)Wname(wp),filename))
  1537.                 {
  1538.                     if(form_alert(2,Afileio[13])==2)
  1539.                     {
  1540.                         wp->w_state &= ~CHANGED; /* rückgängig machen */
  1541.                         Wnewname(wp,filename);
  1542.                         ren_icon(desktop, wp->icon);
  1543.                     }
  1544.                 }
  1545.                 else
  1546.                     wp->w_state &= ~CHANGED; /* rückgängig machen */
  1547.             }
  1548.             if(signal==SIGNULL)
  1549.                 graf_mouse(ARROW,NULL);
  1550.         }
  1551.         else
  1552.         {
  1553.             findfirst(filename,&fileRec,0);
  1554.             if(fileRec.ff_attrib & 1) /* readonly */
  1555.             {
  1556. /* unnötig
  1557.                 while(!findnext(&fileRec)); /* weiter bis zum Ende */
  1558. */
  1559.                 if(form_alert(2,Afileio[14])==2)
  1560.                 {
  1561. #if GEMDOS
  1562.                     Fattrib(filename,1,0);  /* Schreibschutz aufheben */
  1563. #else
  1564.                     chmod(filename,0);
  1565. #endif
  1566.                     goto NOCHMAL;
  1567.                 }
  1568.                 else
  1569.                     wp->w_state&=~CHANGED;
  1570.             }
  1571.             else
  1572.             {
  1573.                 while(!findnext(&fileRec)); /* weiter bis zum Ende */
  1574.                 form_alert(1,Afileio[15]);
  1575.             }
  1576.         }
  1577.         if(signal==SIGNULL)
  1578.         {
  1579.             graf_mouse(M_OFF,NULL);
  1580.             Wcursor(wp);
  1581.             graf_mouse(M_ON,NULL);
  1582.         }
  1583.     }
  1584. }
  1585.  
  1586. void write_file(WINDOW *wp, int newname)
  1587. {
  1588.     char filename[PATH_MAX],openmodus[3];
  1589.     int ascformat=FALSE,k,ret,kstate;
  1590.     static char fpattern[FILENAME_MAX]="*.*";
  1591.  
  1592.     graf_mkstate(&ret,&ret,&ret,&kstate);
  1593.     if(kstate & (K_LSHIFT|K_RSHIFT))     /* bei gedrückter Shifttaste... */
  1594.         strcpy(openmodus,"ab");              /* an Datei anhängen,...*/
  1595.     else
  1596.         strcpy(openmodus,"wb");              /* ...sonst neue Datei      */
  1597.  
  1598.     if(wp)
  1599.     {
  1600.         if(newname)
  1601.         {
  1602.             if(!(kstate & (K_LSHIFT|K_RSHIFT)))
  1603.             {
  1604.                 filename[0]=0;
  1605.                 if(getfilename(filename,fpattern,"",fselmsg[11]))
  1606.                 {
  1607.                     if(access(filename,0))
  1608.                     {
  1609.                         sprintf(iostring,Afileio[12],split_fname(filename));
  1610.                         if(form_alert(1,iostring)==1)
  1611.                             return;
  1612.                     }
  1613.                     k=strlen(filename);
  1614.                     if(filename[k-3]=='G' &&  /*  *.ASC speichern */
  1615.                         filename[k-2]=='E' &&
  1616.                         filename[k-1]=='M')
  1617.                     {
  1618.                         gdosprint(prtmenu,layout,pinstall,wp,METAFILE,filename);
  1619.                         return;
  1620.                     }
  1621.                 }
  1622.                 else
  1623.                     return;
  1624.             }
  1625.             if(kstate & (K_LSHIFT|K_RSHIFT))
  1626.             {
  1627.                 filename[0]=0;
  1628.                 if(!getfilename(filename,fpattern,"",fselmsg[12]))
  1629.                     return;
  1630.             }
  1631.         }
  1632.         else
  1633.         {
  1634.             if(!(kstate & (K_LSHIFT|K_RSHIFT))) /* backup nicht bei Anhängen */
  1635.             {
  1636.                 if(!(wp->w_state & CHANGED))
  1637.                     return;
  1638.                 if(divmenu[DIVBACK].ob_state&SELECTED)
  1639.                 {
  1640.                     strcpy(filename,(char *)Wname(wp));
  1641.                     change_ext(filename,".BAK");
  1642.                     unlink(filename);
  1643.                     rename((char *)Wname(wp),filename);
  1644.                 }
  1645.             }
  1646. /*neu*/  strcpy(filename,(char *)Wname(wp));
  1647.         }
  1648.         ascformat=isascformat(wp->name); /* Extension .ASC? */
  1649.         _write_file(wp, filename, openmodus, newname, ascformat, SIGNULL);
  1650.     }
  1651. }
  1652.  
  1653. void write_block(WINDOW *wp, LINESTRUCT *beg, LINESTRUCT *end)
  1654. {
  1655.     char filename[PATH_MAX];
  1656.     static char fpattern[FILENAME_MAX]="*.*";
  1657.  
  1658.     if(wp && beg && end)
  1659.     {
  1660.         filename[0]=0;
  1661.         if(!getfilename(filename,fpattern,"",fselmsg[13]))
  1662.             return;
  1663.         if(access(filename,0))
  1664.         {
  1665.             sprintf(iostring,Afileio[12],split_fname(filename));
  1666.             if(form_alert(1,iostring)==1)
  1667.                 return;
  1668.         }
  1669.         if(!_write_blk(wp, filename, beg, end))
  1670.         {
  1671.             form_alert(1,Afileio[16]);
  1672.         }
  1673.     }
  1674. }
  1675.  
  1676. #if GEMDOS
  1677. int getbootdev(void)
  1678. {
  1679.     int drv;
  1680.     long stack;
  1681.  
  1682.     stack=Super(0L);
  1683.     drv= *(int *)0x446;
  1684.     Super((void *)stack);
  1685.     return(drv);
  1686. }
  1687.  
  1688. int create_clip(void)
  1689. {
  1690.     char *cp, *pathname="@:\\CLIPBRD";
  1691.  
  1692.     if((cp=getenv("CLIPBRD")) || (cp=getenv("SCRAPDIR")))
  1693.         return(scrp_write(cp));
  1694.     else
  1695.     {
  1696.         pathname[0]=(char)(getbootdev()+'A');
  1697.         Dcreate(pathname);
  1698.         return(scrp_write(pathname));
  1699.     }
  1700. }
  1701.  
  1702. int scrp_clear(void) /* Clipbrd löschen, für Atari */
  1703. {
  1704.     char filename[PATH_MAX],path[PATH_MAX];
  1705.     struct ffblk fileRec;
  1706.  
  1707.     scrp_read(path);
  1708.     if(*path)
  1709.     {
  1710.         complete_path(path);
  1711.         strcpy(filename,path);
  1712.         strcat(filename,"SCRAP.*");
  1713.         if(!findfirst(filename,&fileRec,0))
  1714.         {
  1715.             strcpy(filename,path);
  1716.             strcat(filename,fileRec.ff_name);
  1717.             unlink(filename);
  1718.             while(!findnext(&fileRec))
  1719.             {
  1720.                 strcpy(filename,path);
  1721.                 strcat(filename,fileRec.ff_name);
  1722.                 unlink(filename);
  1723.             }
  1724.             return(TRUE);
  1725.         }
  1726.     }
  1727.     return(FALSE);
  1728. }
  1729. #endif
  1730.  
  1731. void write_clip(WINDOW *wp, LINESTRUCT *begcut, LINESTRUCT *endcut)
  1732. {
  1733.     char filename[PATH_MAX];
  1734.     static int first=TRUE;
  1735.  
  1736.     if(wp && begcut && endcut)
  1737.     {
  1738.         scrp_read(filename);
  1739.         if(!*filename)
  1740.         {
  1741. #if GEMDOS
  1742.             if(create_clip())
  1743.                 scrp_read(filename);
  1744.             else
  1745.             {
  1746.                 form_alert(1,Afileio[17]);
  1747.                 return;
  1748.             }
  1749. #endif
  1750.         }
  1751.         else
  1752.         {
  1753.             if(first) /* beim erstenmal Clipbrd löschen */
  1754.             {
  1755.                 scrp_clear();
  1756.                 first=FALSE;
  1757.             }
  1758.         }
  1759.         complete_path(filename);
  1760.         strcat(filename,"SCRAP.TXT");
  1761.         if(!_write_blk(wp, filename, begcut, endcut))
  1762.         {
  1763.             form_alert(1,Afileio[25]);
  1764.         }
  1765.         inst_clipboard_icon(desktop,DESKICNB,DESKICNC,FALSE);
  1766.     }
  1767. }
  1768.  
  1769. void Gsave(WINDOW *wp) /* GEMINI: nach $TRASHDIR */
  1770. {
  1771.     char *cp,filename[PATH_MAX];
  1772.     LINESTRUCT *beg,*end,*help;
  1773.     if(wp && (divmenu[DIVPAPER].ob_state&SELECTED))
  1774.     {
  1775.         if(cp=getenv("TRASHDIR"))
  1776.         {
  1777.             strcpy(filename,cp);
  1778.               complete_path(filename);
  1779.             strcat(filename,split_fname((char *)Wname(wp)));
  1780.             for(help=beg=wp->fstr; help; help=help->next)
  1781.             {
  1782.                 help->begcol=0;
  1783.                 help->endcol=STRING_LENGTH;
  1784.                 end=help;
  1785.             }
  1786.             if(_write_blk(wp, filename, beg, end))
  1787.             {
  1788.                 wp->w_state&=~CHANGED;
  1789.                 inst_trashcan_icon(desktop,DESKICN8,DESKICND,FALSE);
  1790.             }
  1791.             else
  1792.             {
  1793.                 form_alert(1,Afileio[18]);
  1794.             }
  1795.         }
  1796.     }
  1797. }
  1798.  
  1799. delete_file(void)
  1800. {
  1801.     char filename[PATH_MAX];
  1802.     struct ffblk fileRec;
  1803.     static char fpattern[FILENAME_MAX]="*.*";
  1804.  
  1805. #if GEMDOS
  1806. #define MAXPATHS 7
  1807.     int i;
  1808.     char *cp;
  1809.     extern char lpath[MAXPATHS][PATH_MAX];
  1810.     extern char *lname[MAXPATHS];
  1811.     extern SLCT_STR *slct;
  1812. #endif
  1813.  
  1814. #if GEMDOS
  1815.     if( slct_check(0x0100))
  1816.     {
  1817.         slct_morenames(0, MAXPATHS,lname); /* we want more */
  1818.     }
  1819. #endif
  1820.     filename[0]=0;
  1821.     if(!getfilename(filename,fpattern,"@",fselmsg[14]))
  1822.         return;
  1823.     if(!filename[0]) /* Kunde will nicht */
  1824.         return;
  1825. #if GEMDOS
  1826.     if(slct && (slct->out_count>1))
  1827.     {
  1828.         slct->out_count=min(slct->out_count,MAXPATHS);
  1829.         for(i=0; i<slct->out_count; i++)
  1830.         {  /* Pfadnamen zusammenbasteln */
  1831.             if((cp=strrchr(filename,'\\'))!=NULL || (cp=strrchr(filename,'/'))!=NULL)
  1832.             {
  1833.                 cp[1]=0;
  1834.                 strcat(filename,lpath[i]);
  1835.                 {
  1836.                     sprintf(alertstr,Afileio[19],lpath[i]);
  1837.                     if(form_alert(2,alertstr)==2)
  1838.                     {
  1839.                         graf_mouse(BUSY_BEE,NULL);
  1840.                         if(unlink(filename)!=0)
  1841.                             form_alert(1,Afileio[23]);
  1842.                         graf_mouse(ARROW,NULL);
  1843.                     }
  1844.                 }
  1845.             }
  1846.         }
  1847.     }
  1848.     else
  1849. #endif
  1850.     {
  1851.         sprintf(alertstr,Afileio[19],split_fname(filename));
  1852.         if(form_alert(2,alertstr)==2)
  1853.         {
  1854.             graf_mouse(BUSY_BEE,NULL);
  1855.             if(!findfirst(filename,&fileRec,0))
  1856.             {
  1857.                 cut_path(filename);
  1858.                 strcat(filename,fileRec.ff_name);
  1859.                 if(unlink(filename)!=0)
  1860.                     form_alert(1,Afileio[23]);
  1861.                 while(!findnext(&fileRec))
  1862.                 {
  1863.                     cut_path(filename);
  1864.                     strcat(filename,fileRec.ff_name);
  1865.                     if(unlink(filename)!=0)
  1866.                         form_alert(1,Afileio[23]);
  1867.                 }
  1868.                 inst_trashcan_icon(desktop,DESKICN8,DESKICND,FALSE);
  1869.                 if(!stricmp((char *)split_fname(filename),"SCRAP.TXT"))
  1870.                     inst_clipboard_icon(desktop,DESKICNB,DESKICNC,FALSE);
  1871.             }
  1872.             else
  1873.                 form_alert(1,Afileio[20]);
  1874.             graf_mouse(ARROW,NULL);
  1875.         }
  1876.     }
  1877. }
  1878.  
  1879. char errorstr[PATH_MAX]="";
  1880.  
  1881. static void nofilearg(char *arg, char what)
  1882. {
  1883.     WINDOW *wp;
  1884.     char *cp;
  1885.     int window;
  1886.  
  1887.     switch(what)
  1888.     {
  1889.         case '-':
  1890.             switch(arg[1])
  1891.             {
  1892.                 case 't':
  1893.                     window=atoi(&arg[2]);
  1894.                     if(window<0)
  1895.                         window+=Wcount(OPENED);
  1896.                     if(window>0 && window<MAXWINDOWS)
  1897.                         Wtop(&_wind[window]);
  1898.                     break;
  1899.                 case 'z': /* -z50s25 = Zeile 50 Spalte 25 */
  1900.                     if(wp=Wgettop())
  1901.                     {
  1902.                         cp=strchr(arg,'s');
  1903.                         if(cp)
  1904.                         {
  1905.                             *cp=0;
  1906.                             wp->cspos=wp->col=atoi(cp+1L)-1;
  1907.                         }
  1908.                         hndl_goto(wp,NULL/*gotomenu*/,atol(&arg[2]));
  1909.                     }
  1910.                     break;
  1911.                 default:
  1912.                     break;
  1913.             }
  1914.             break;
  1915.         case '\"':
  1916.             if(arg[strlen(arg)-1] == '\"') /* für Compilerfehlermeldung */
  1917.             {
  1918.                 strcpy(errorstr,arg);
  1919.                 if(wp=Wgettop())
  1920.                 {  /* erst normal Inforzeile, um Timer auszutricksen */
  1921.                     if(wp->kind & INFO)
  1922.                     {
  1923.                         graf_mouse(M_OFF,NULL);
  1924.                         Wcursor(wp);
  1925.                         Wsetrcinfo(wp);
  1926.                         Wcursor(wp);
  1927.                         graf_mouse(M_ON,NULL);
  1928.                         wind_set(wp->wihandle,WF_INFO,errorstr);
  1929.                     }
  1930.                     else
  1931.                         form_alert(1,Afileio[21]);
  1932.                 }
  1933.             }
  1934.             break;
  1935.         default:
  1936.             switch(what)
  1937.             {
  1938.                 case 'z': /* 50 = Zeile 50 */
  1939.                     if(wp=Wgettop())
  1940.                     {
  1941.                         wp->cspos=wp->col=0;
  1942.                         hndl_goto(wp,NULL/*gotomenu*/,atol(arg));
  1943.                     }
  1944.                     break;
  1945.                 case 's': /* (xx) 25 = Spalte 25 */
  1946.                     if(wp=Wgettop())
  1947.                     {
  1948.                         wp->cspos=wp->col=atoi(arg)-1;
  1949.                     }
  1950.                     break;
  1951.                 default:
  1952.                     break;
  1953.             }
  1954.             break;
  1955.     }
  1956. }
  1957.  
  1958. int isnumeric(char *num)
  1959. {
  1960.     int i,k=strlen(num);
  1961.     for(i=0; i<k; i++)
  1962.         if(!isdigit(num[i]))
  1963.             return(FALSE);
  1964.     return(TRUE);
  1965. }
  1966.  
  1967. char *stristr(char *s1, char *s2);
  1968.  
  1969. char *isinffile(int argc, char *argv[]) /* *.INF File dabei? */
  1970. {
  1971.     register int i;
  1972.     if(argc>1)
  1973.         for(i=1; i<argc; i++)
  1974.             if(stristr(argv[i],"7UP") && stristr(argv[i],".INF"))
  1975.                 return(argv[i]);
  1976.     return(NULL);
  1977. }
  1978.  
  1979. int file_input(int argc, char *argv[])
  1980. {
  1981. #if MSDOS
  1982.     FILE *fp;
  1983.     struct ffblk fileRec;
  1984.     char filename[PATH_MAX];
  1985.     static char fpattern[FILENAME_MAX]="*.*";
  1986. #endif
  1987.     int i,k,msgbuf[8];
  1988.     extern int gl_apid;
  1989.     
  1990.     if(argc>1)
  1991.     {
  1992.         for(i=1,k=1; i<argc && k<MAXWINDOWS; i++)
  1993.         {
  1994.             if(*argv[i] == '\"')
  1995.                 nofilearg(argv[i],'\"');
  1996.             if(*argv[i] == '-')
  1997.                 nofilearg(argv[i],'-');
  1998.             if(!isnumeric(argv[i-1]) && isnumeric(argv[i]))
  1999.                 nofilearg(argv[i],'z');
  2000.             if(isnumeric(argv[i-1]) && isnumeric(argv[i]))
  2001.                 nofilearg(argv[i],'s');
  2002.             if(!(stristr(argv[i],"7UP") && stristr(argv[i],".INF")) &&
  2003.                 !isnumeric(argv[i]) && *argv[i]!='-' && *argv[i]!='\"')
  2004.             {
  2005.                 Wreadtempfile(argv[i],FALSE);
  2006.                 k++;
  2007.             }
  2008.         }
  2009.     }
  2010.     else
  2011.     {
  2012. #if GEMDOS
  2013.         if((get_cookie('MagX') &&
  2014.              shel_read(alertstr,&alertstr[128]) &&
  2015.              !memcmp(&alertstr[128],"\0\0AUTO",6)) ||
  2016.             (get_cookie('MiNT') &&
  2017.              (_GemParBlk.global[1] != 1) &&
  2018.              shel_read(alertstr,&alertstr[128]) &&
  2019.              strstr(strupr(alertstr),"AUTOGEM")))
  2020.         {
  2021.             winmenu[WINNEW -1].ob_height-=(2*boxh);
  2022.             winmenu[WINQUIT-1].ob_flags|=HIDETREE;
  2023.             winmenu[WINQUIT  ].ob_state|=DISABLED;
  2024.             winmenu[WINQUIT  ].ob_flags|=HIDETREE;
  2025.             return;
  2026.         }
  2027. #endif
  2028.         if(TRUE/*!readnames()*/)  /* nur FSB, wenn keine alten Dateien oder Parameter */
  2029.         {
  2030. #if GEMDOS
  2031.             msgbuf[0]=MN_SELECTED;
  2032.             msgbuf[1]=gl_apid;
  2033.             msgbuf[2]=0;
  2034.             msgbuf[3]=WINFILE;
  2035.             msgbuf[4]=WINOPEN;
  2036.             msgbuf[5]=0;
  2037.             msgbuf[6]=0;
  2038.             msgbuf[7]=0;
  2039.             menu_tnormal(winmenu,WINFILE,0);
  2040. #if OLDTOS
  2041.             wind_update(END_UPDATE);
  2042. #endif
  2043.             appl_write(gl_apid,16,msgbuf);
  2044. #if OLDTOS
  2045.             wind_update(BEG_UPDATE);
  2046. #endif
  2047. #else
  2048.             filename[0]=0;
  2049.             if(!getfilename(filename,fpattern,"",fselmsg[15]))
  2050.                 return;
  2051.             if(!findfirst(filename,&fileRec,0))
  2052.             {
  2053.                 cut_path(filename);
  2054.                 strcat(filename,fileRec.ff_name);
  2055.                 if(!Wreadtempfile(filename,FALSE))
  2056.                     return;
  2057.                 while(!findnext(&fileRec))
  2058.                 {
  2059.                     cut_path(filename);
  2060.                     strcat(filename,fileRec.ff_name);
  2061.                     if(!Wreadtempfile(filename,FALSE))
  2062.                         return;
  2063.                 }
  2064.             }
  2065.             else
  2066.             {
  2067.                 sprintf(alertstr,Afileio[8],(char *)split_fname(filename));
  2068.                 if(form_alert(2,alertstr)==2)
  2069.                     Wnewfile(filename);
  2070.             }
  2071. if(0)
  2072. form_alert(1,"[0][][ok]");
  2073. #endif
  2074.         }
  2075.     }
  2076. }
  2077.  
  2078. void loadfiles(char *TV_path, char *TV_pattern) /* evtl. Treeviewpfade */
  2079. {
  2080.     register int i;
  2081.     char *cp;
  2082.     char filename[PATH_MAX];
  2083.     static char fpattern[FILENAME_MAX]="*.*";
  2084.     struct ffblk fileRec;
  2085.  
  2086. #if GEMDOS
  2087. #define MAXPATHS 7
  2088.     extern char lpath[MAXPATHS][PATH_MAX];
  2089.     extern char *lname[MAXPATHS];
  2090.     extern SLCT_STR *slct;
  2091.  
  2092.     if( slct_check(0x0100))
  2093.     {
  2094.         slct_morenames(0, MAXPATHS,lname); /* we want more */
  2095.     }
  2096. #endif
  2097.     filename[0]=0;
  2098.     if(*TV_path) /* Treeview ist am Werk, Pfade übernehmen */
  2099.     {
  2100.         strcpy(filename,TV_path);
  2101.         strcpy(fpattern,TV_pattern);
  2102.     }
  2103.     if(!getfilename(filename,fpattern,"",fselmsg[16]))
  2104.         return;
  2105.     if(!filename[0]) /* Kunde will nicht */
  2106.         return;
  2107. #if GEMDOS
  2108.     if(slct && (slct->out_count>1))
  2109.     {
  2110.         slct->out_count=min(slct->out_count,MAXWINDOWS-Wcount(CREATED)-1);
  2111.         for(i=0; i<slct->out_count; i++)
  2112.         {  /* Pfadnamen zusammenbasteln */
  2113.             if((cp=strrchr(filename,'\\'))!=NULL || (cp=strrchr(filename,'/'))!=NULL)
  2114.             {
  2115.                 cp[1]=0;
  2116.                 strcat(filename,lpath[i]);
  2117.                 if(!Wreadtempfile(filename,FALSE))
  2118.                     break;
  2119.             }
  2120.         }
  2121.     }
  2122.     else
  2123. #endif
  2124.     {
  2125.         if(get_cookie('MiNT'))
  2126.         {
  2127.             if(!Wreadtempfile(filename,FALSE))
  2128.             {
  2129.                 sprintf(alertstr,Afileio[8],(char *)split_fname(filename));
  2130.                 if(form_alert(2,alertstr)==2)
  2131.                     Wnewfile(filename);
  2132.             }
  2133.         }
  2134.         else
  2135.         {
  2136.             if(!findfirst(filename,&fileRec,0))
  2137.             {
  2138.                 cut_path(filename);
  2139.                 strcat(filename,fileRec.ff_name);
  2140.                 if(!Wreadtempfile(filename,FALSE))
  2141.                     return;
  2142.                 while(!findnext(&fileRec))
  2143.                 {
  2144.                     cut_path(filename);
  2145.                     strcat(filename,fileRec.ff_name);
  2146.                     if(!Wreadtempfile(filename,FALSE))
  2147.                         break;
  2148.                 }
  2149.             }
  2150.             else
  2151.             {
  2152.                 sprintf(alertstr,Afileio[8],(char *)split_fname(filename));
  2153.                 if(form_alert(2,alertstr)==2)
  2154.                     Wnewfile(filename);
  2155.             }
  2156.         }
  2157.     }
  2158. }
  2159.